package com.zingrow.web.configure.microuser.controller;

import java.io.File;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.support.DefaultMultipartHttpServletRequest;

import com.idaycrm.idaybase.utils.JsonUtils;
import com.zingrow.common.ReturnStandardDataFormat;
import com.zingrow.common.utils.CommonUtils;
import com.zingrow.common.utils.EncodingUtils;
import com.zingrow.common.utils.ExcelUtils;
import com.zingrow.common.utils.OptClass;
import com.zingrow.common.utils.PageView;
import com.zingrow.web.base.CodeMsg;
import com.zingrow.web.base.controller.BaseController;
import com.zingrow.web.base.enums.Menu;
import com.zingrow.web.base.enums.Operation;
import com.zingrow.web.common.utils.AnalyzeResult;
import com.zingrow.web.configure.iformation.model.Iformation;
import com.zingrow.web.configure.iformation.service.IIformationService;
import com.zingrow.web.configure.microuser.model.Microuser;
import com.zingrow.web.configure.microuser.service.IMicrouserService;
import com.zingrow.web.support.operate.model.OptRecord;
import com.zingrow.web.support.operate.service.IOptRecordService;
import com.zingrow.web.user.model.ActiveUser;
import com.zingrow.web.user.model.UserPermission;
import com.zingrow.web.user.service.IPermissionService;
@Controller
@RequestMapping(value="/microuser/",produces="application/json;charset=UTF-8")
public class MicrouserController extends BaseController {
	@Autowired
	private IMicrouserService microuserService;
	@Autowired
	private IOptRecordService optRecordService;
	@Autowired
	private IIformationService iformationService;
	@Autowired
	private IPermissionService permissionService;
	@Autowired
	private IOptRecordService ioptRecordService;
	@ResponseBody
	@RequestMapping("queryParams")
	public String queryParams(HttpServletRequest request,HttpServletResponse response,Integer pageIndex,
			Integer pageSize,String microuser_bloggerId,String microuser_blogger,String microuser_bloggerUrl,Integer is_exprot,String sp){
		List<Microuser> list = new ArrayList<Microuser>();
		ReturnStandardDataFormat StandardData = new ReturnStandardDataFormat(CodeMsg.CODE_ERROR,CodeMsg.MSG_ERROR,list);
		PageView pageView = null;
		try {
			if(pageIndex == null || pageIndex <= 0 ){
				pageIndex = 1;
			}
			if(pageSize == null || pageSize <= 0){
				pageSize = 10;
			}
			//分页参数赋值给pageView
			pageView = new PageView(pageSize,pageIndex);
			//转码
			if(microuser_bloggerId != null || "".equals(microuser_bloggerId)){
				microuser_bloggerId = EncodingUtils.fixUrlParamEncoding(request, microuser_bloggerId);
			}
			if(microuser_blogger != null || "".equals(microuser_blogger)){
				microuser_blogger = EncodingUtils.fixUrlParamEncoding(request, microuser_blogger);
			}
			if(microuser_bloggerUrl != null || "".equals(microuser_bloggerUrl)){
				microuser_bloggerUrl = EncodingUtils.fixUrlParamEncoding(request, microuser_bloggerUrl);
			}
			list = microuserService.queryParams(pageView, microuser_bloggerId, microuser_blogger, microuser_bloggerUrl,is_exprot);
			if("1".equals(sp))
			{
				//新增一条操作记录
				ActiveUser opuser = getUser(request);//获取操作用户
				OptRecord s = new OptClass().weibo_query(opuser,Menu.Resourceallocation.toString(),
						Menu.microuser.toString(),Operation.query.toString(),microuser_bloggerId,microuser_blogger,microuser_bloggerUrl);
				if(!s.getOptName().equals("null"))	
				ioptRecordService.insert(s);
			}
		} catch (Exception e) {
			log.error("根据参数查询异常");
			ActiveUser opuser = getUser(request);//获取操作用户
			OptRecord s = new OptClass().recordabnormality(opuser,"微博配置根据参数查询异常");
			ioptRecordService.insert(s);
			StandardData.setReturnCode(CodeMsg.CODE_EXCEPTION);
			StandardData.setReturnMessage(CodeMsg.MSG_EXCEPTION);
			StandardData.setReturnData(list);
		}
		StandardData.setReturnData(list);
		StandardData.setReturnCode(CodeMsg.CODE_OK);
		StandardData.setReturnMessage(CodeMsg.MSG_OK);
		StandardData.setTotalPages(pageView.getPageCount());
		StandardData.setTotalRecords(pageView.getRowCount());
		return JsonUtils.toString(StandardData,"yyyy-MM-dd HH:mm:ss");
	}
	//删除
	@ResponseBody
	@RequestMapping("deleteMicrouser")
	public String deleteMicrouser(HttpServletRequest request,HttpServletResponse response,
			Integer microuser_id,String microuser_bloggerId){
		ReturnStandardDataFormat StandardData = new ReturnStandardDataFormat(CodeMsg.CODE_ERROR,CodeMsg.MSG_ERROR,null);
		try {
			//判断参数值
			if(CommonUtils.isObjectNull(microuser_id)){
				StandardData.setReturnCode(CodeMsg.CODE_ERROR_PARAMS);
				StandardData.setReturnMessage(CodeMsg.MSG_ERROR_PARAMS);
				return JsonUtils.toString(StandardData, "yyyy-MM-dd HH:mm:ss");
			}
			//字符串转换
			if(CommonUtils.isStrNotNull(microuser_bloggerId)){
				microuser_bloggerId = EncodingUtils.fixUrlParamEncoding(request, microuser_bloggerId);
			}
			Microuser ymicrouser = microuserService.queryById(microuser_id);
			if(microuserService.deleteMicrouser(microuser_id)){
				//操作记录
				ActiveUser opuser = getUser(request);//获取操作用户
				OptRecord s = new OptClass().weibo_delete(opuser,Menu.Resourceallocation.toString(),
						Menu.microuser.toString(),Operation.delete.toString(),ymicrouser);
				ioptRecordService.insert(s);	
				//操作成功
				StandardData.setReturnCode(CodeMsg.CODE_OK);
				StandardData.setReturnMessage(CodeMsg.MSG_OK);
			}else{
				ActiveUser opuser = getUser(request);//获取操作用户
				OptRecord s = new OptClass().recordabnormality(opuser,"微博配置删除失败");
				ioptRecordService.insert(s);
				StandardData.setReturnCode(CodeMsg.CODE_ERROR);
				StandardData.setReturnMessage(CodeMsg.MSG_ERROR);
			}
		} catch (Exception e) {
			log.error("根据参数删除异常");
			ActiveUser opuser = getUser(request);//获取操作用户
			OptRecord s = new OptClass().recordabnormality(opuser,"频道配置删除异常");
			ioptRecordService.insert(s);
			StandardData.setReturnCode(CodeMsg.CODE_EXCEPTION);
			StandardData.setReturnMessage(CodeMsg.MSG_EXCEPTION);
		}
		return JsonUtils.toString(StandardData, "yyyy-MM-dd HH:mm:ss");
	}
	//新增
	@ResponseBody
	@RequestMapping("addMicrouser")
	public String addMicrouser(HttpServletRequest request,HttpServletResponse response,Microuser microuser){
		ReturnStandardDataFormat standardData = new ReturnStandardDataFormat(CodeMsg.CODE_ERROR,CodeMsg.MSG_ERROR,null);
		try {
			//判断参数是否正确
			if(CommonUtils.isStrNull(microuser.getMicrouser_bloggerId())||CommonUtils.isStrNull(microuser.getMicrouser_blogger())||
				CommonUtils.isStrNull(microuser.getMicrouser_bloggerUrl())){
				
				standardData.setReturnCode(CodeMsg.CODE_ERROR_PARAMS);
				standardData.setReturnMessage(CodeMsg.MSG_ERROR_PARAMS);
				return JsonUtils.toString(standardData, "yyyy-MM-dd HH:mm:ss");
			}else{
				//参数转码
				microuser.setMicrouser_bloggerId(EncodingUtils.fixUrlParamEncoding(request, microuser.getMicrouser_bloggerId()));
				microuser.setMicrouser_blogger(EncodingUtils.fixUrlParamEncoding(request, microuser.getMicrouser_blogger()));
				microuser.setMicrouser_bloggerUrl(EncodingUtils.fixUrlParamEncoding(request, microuser.getMicrouser_bloggerUrl()));
			}
			//判断微博号是否同名
			if(microuserService.queryByid(null,microuser.getMicrouser_bloggerUrl(),microuser.getMicrouser_blogger(),microuser.getMicrouser_bloggerId())){
				 standardData.setReturnCode(CodeMsg.CODE_ERROR_OTHER);
				 standardData.setReturnMessage("用户名或用户id或博主地址已存在，请重新输入");
				 return JsonUtils.toString(standardData, "yyyy-MM-dd HH:mm:ss");
			}
			//调用新增
			if(microuserService.addMicrouser(microuser)){
				//操作记录
				ActiveUser opuser = getUser(request);//获取操作用户
				OptRecord s = new OptClass().weibo_add(opuser,Menu.Resourceallocation.toString(),
						Menu.microuser.toString(),Operation.insert.toString(),microuser);
				ioptRecordService.insert(s);	
				//操作成功
				standardData.setReturnCode(CodeMsg.CODE_OK);
				standardData.setReturnMessage(CodeMsg.MSG_OK);
			}else{
				standardData.setReturnCode(CodeMsg.CODE_ERROR);
				standardData.setReturnMessage(CodeMsg.MSG_ERROR);
			}
		} catch (Exception e) {
			log.error("微博号新增异常");
			ActiveUser opuser = getUser(request);//获取操作用户
			OptRecord s = new OptClass().recordabnormality(opuser,"微博号配置新增异常");
			ioptRecordService.insert(s);
			standardData.setReturnCode(CodeMsg.CODE_EXCEPTION);
			standardData.setReturnMessage(CodeMsg.MSG_EXCEPTION);
		}
		return JsonUtils.toString(standardData, "yyyy-MM-dd HH:mm:ss");
	}
	//单个查询
	@ResponseBody
	@RequestMapping("queryById")
	public String queryById(HttpServletRequest request,HttpServletResponse response,Integer microuser_id){
		Microuser microuser = new Microuser();
		ReturnStandardDataFormat standardData = new ReturnStandardDataFormat(CodeMsg.CODE_ERROR,CodeMsg.MSG_ERROR,null);
		try {
			//判断参数是否正确
			if(CommonUtils.isObjectNull(microuser_id)){
				standardData.setReturnCode(CodeMsg.CODE_ERROR_PARAMS);
				standardData.setReturnMessage(CodeMsg.MSG_ERROR_PARAMS);
				return JsonUtils.toString(standardData, "yyyy-MM-dd HH:mm:ss");
			}
			microuser = microuserService.queryById(microuser_id);
		} catch (Exception e) {
			log.error("根据编号查询异常");
			log.error(e.getMessage());
			standardData.setReturnCode(CodeMsg.CODE_EXCEPTION);
			standardData.setReturnMessage(CodeMsg.MSG_EXCEPTION);
			standardData.setReturnData(microuser);
		}
		standardData.setReturnData(microuser);
		standardData.setReturnCode(CodeMsg.CODE_OK);
		standardData.setReturnMessage(CodeMsg.MSG_OK);
		return JsonUtils.toString(standardData, "yyyy-MM-dd HH:mm:ss");
	}
	//修改
	@ResponseBody
	@RequestMapping("modifyMicrouser")
	public String modifyMicrouser(HttpServletRequest request,HttpServletResponse response,Microuser microuser){
		ReturnStandardDataFormat standardData = new ReturnStandardDataFormat(CodeMsg.CODE_ERROR,CodeMsg.MSG_ERROR,null);
		try {
			//判断参数是否正确
			if(CommonUtils.isStrNull(microuser.getMicrouser_bloggerId())||CommonUtils.isStrNull(microuser.getMicrouser_bloggerUrl())||
				CommonUtils.isStrNull(microuser.getMicrouser_blogger())){
				
				standardData.setReturnCode(CodeMsg.CODE_ERROR_PARAMS);
				standardData.setReturnMessage(CodeMsg.MSG_ERROR_PARAMS);
				return JsonUtils.toString(standardData, "yyyy-MM-dd HH:mm:ss");
			}else{
				//转码
				microuser.setMicrouser_bloggerId(EncodingUtils.fixUrlParamEncoding(request, microuser.getMicrouser_bloggerId()));
				microuser.setMicrouser_blogger(EncodingUtils.fixUrlParamEncoding(request, microuser.getMicrouser_blogger()));
				microuser.setMicrouser_bloggerUrl(EncodingUtils.fixUrlParamEncoding(request, microuser.getMicrouser_bloggerUrl()));
			}
			//判断同名
			if(microuserService.queryByid(microuser.getMicrouser_id(),microuser.getMicrouser_bloggerUrl(),microuser.getMicrouser_blogger(),microuser.getMicrouser_bloggerId())){
				standardData.setReturnCode(CodeMsg.CODE_ERROR_OTHER);
				standardData.setReturnMessage("用户名或用户id或博主地址已存在，请重新输入");
				return JsonUtils.toString(standardData, "yyyy-MM-dd HH:mm:ss");
			}
			Microuser ymicrouser=microuserService.queryById(microuser.getMicrouser_id());
			//调用修改
			if(microuserService.modifyMicrouser(microuser)){
				//操作记录
				ActiveUser opuser = getUser(request);//获取操作用户
				OptRecord s = new OptClass().weibo_updata(opuser,Menu.Resourceallocation.toString(),
						Menu.microuser.toString(),Operation.update.toString(),ymicrouser,microuser);
				ioptRecordService.insert(s);	
				//操作成功
				standardData.setReturnCode(CodeMsg.CODE_OK);
				standardData.setReturnMessage(CodeMsg.MSG_OK);
			}else{
				standardData.setReturnCode(CodeMsg.CODE_ERROR);
				standardData.setReturnMessage(CodeMsg.MSG_ERROR);
			}
		} catch (Exception e) {
			log.error("修改微博号异常");
			ActiveUser opuser = getUser(request);//获取操作用户
			OptRecord s = new OptClass().recordabnormality(opuser,"微博号配置修改频道异常");
			ioptRecordService.insert(s);
			standardData.setReturnCode(CodeMsg.CODE_EXCEPTION);
			standardData.setReturnMessage(CodeMsg.MSG_ERROR);
		}
		return JsonUtils.toString(standardData, "yyyy-MM-dd HH:mm:ss");
	}
	//查询全部的接口
	@ResponseBody
	@RequestMapping("queryByIdName")
	public String queryByIdName(HttpServletRequest request,HttpServletResponse response,Integer pageIndex,Integer pageSize){
		List<Microuser> list = new ArrayList<Microuser>();
		ReturnStandardDataFormat standardData = new ReturnStandardDataFormat(CodeMsg.CODE_ERROR,CodeMsg.MSG_ERROR,list);
		PageView pageView = null;
		try {
			if(pageIndex == null || pageIndex <= 0 ){
				pageIndex = 1;
			}
			if(pageSize == null || pageSize <= 0){
				pageSize = 10;
			}
				//分页参数赋值给pageView
				pageView = new PageView(pageSize,pageIndex);
			list = microuserService.queryByIdName(pageView);
		} catch (Exception e) {
			log.error("查询异常");
			log.error(e.getMessage());
			standardData.setReturnCode(CodeMsg.CODE_EXCEPTION);
			standardData.setReturnMessage(CodeMsg.MSG_EXCEPTION);
			standardData.setReturnData(list);
		}
		standardData.setReturnData(list);
		standardData.setReturnCode(CodeMsg.CODE_OK);
		standardData.setReturnMessage(CodeMsg.MSG_OK);
		standardData.setTotalPages(pageView.getPageCount());
		standardData.setTotalRecords(pageView.getRowCount());
		return JsonUtils.toString(standardData, "yyyy-MM-dd HH:mm:ss");
	}
	//导出模板
	@ResponseBody
	@RequestMapping("exportExcelForModel")
	public String exportExcelForModel(HttpServletRequest request,HttpServletResponse response){
		ReturnStandardDataFormat standardData = new ReturnStandardDataFormat(CodeMsg.CODE_ERROR,CodeMsg.MSG_ERROR,null);
		List<Microuser> list = new ArrayList<Microuser>();
		try {
			List<String> titles = Arrays.asList("微博id","微博名","博主url");
			List<String> paramsName = Arrays.asList("microuser_bloggerId","microuser_blogger",
					"microuser_bloggerUrl");
			OutputStream out = null;
			try {
				//获取输出流
				out = response.getOutputStream();
				//清空流
				response.reset();
				//定义响应输出类型
				response.setContentType("application/msexcel");
				//定义文件输出头
				response.setHeader("Content-disposition", 
						"attachment; filename=" + new String("微博号置模版".getBytes("GBK"), "iso8859-1") + ".xls");
				ExcelUtils.exportExcel(titles, paramsName, list, out);
			} catch (Exception e) {
				log.error(e.getMessage());
			}finally{
				out.close();
			}
			ActiveUser opuser = getUser(request);//获取操作用户
			OptRecord s = new OptClass().modelxz(opuser,Menu.Resourceallocation.toString(),
					Menu.microuser.toString(),Operation.modelxz.toString(),"导入模板下载");
			ioptRecordService.insert(s);	
		} catch (Exception e) {
			log.error(e.getMessage());
		}
		return JsonUtils.toString(standardData, "yyyy-MM-dd HH:mm:ss");
	}
	//导出
	@ResponseBody
	@RequestMapping("exportExcelForPageData")
	public String exportExcelForPageData(HttpServletRequest request,HttpServletResponse response,String microuser_id){
		ReturnStandardDataFormat standardData = new ReturnStandardDataFormat(CodeMsg.CODE_ERROR,CodeMsg.MSG_ERROR,null);
		try {
			//定义表头
			List<String> titls = Arrays.asList("微博编号","标签值","微博用户id","微博用户名","博主url地址","状态");
			//定义表的字段名
			List<String> paramsName = Arrays.asList("microuser_id","tagvalue_id","microuser_bloggerId",
					"microuser_blogger","microuser_bloggerUrl","is_deletes");
			//处理传入的id
			List<Integer> idlist = new ArrayList<Integer>();
			List<Microuser> microuser = null;
			if(StringUtils.isNoneBlank(microuser_id)){
				//分割id
				for (String strids : microuser_id.split(",")) {
					idlist.add(Integer.valueOf(strids));
				}
				microuser = microuserService.queryMicrouserbyid(idlist);
			}
			//定义一个输出流
			OutputStream out = null;
			try {
				//获取流
				out = response.getOutputStream();
				//清空流
				response.reset();
				//定义响应输出类型
				response.setContentType("application/msexcel");
				//设置文件输出头
				response.setHeader("Content-disposition",
						"attachment; filename=" + new String("微博信息".getBytes("GBK"), "iso8859-1") + ".xls");
				ExcelUtils.exportExcel(titls, paramsName, microuser, out);
			} catch (Exception e) {
				log.error(e.getMessage());
			}finally{
				//关闭流
				out.close();
			}
			//新增一条操作记录
			//操作日志
			ActiveUser opuser = getUser(request);//获取操作用户
			OptRecord s = new OptClass().goiss(opuser,Menu.Resourceallocation.toString(),
					Menu.microuser.toString(),Operation.daochu.toString(),idlist.size());
			ioptRecordService.insert(s);	
		} catch (Exception e) {
			log.error(e.getMessage());
		}
		return JsonUtils.toString(standardData, "yyyy-MM-dd HH:mm:ss");
	}
	
	//新方案根据类别查询微博信息
	@ResponseBody
    @RequestMapping("queryMicroserByType")
    public String queryMicroserByType(HttpServletRequest request,HttpServletResponse response,Integer pageIndex,
            Integer pageSize,String microuser_bloggerId,
            String microuser_blogger,String ifm_id,String types){
        List<Microuser> list = new ArrayList<Microuser>();
        ReturnStandardDataFormat StandardData = new ReturnStandardDataFormat(CodeMsg.CODE_ERROR,CodeMsg.MSG_ERROR,list);
        PageView pageView = null;
        try {
        	List<String> k_1=new ArrayList<String>();
        	String[] s_1=new String[500];
        	if(!ifm_id.equals(null)&&ifm_id!="")
        	{
        	int s=Integer.parseInt(ifm_id);
        	Iformation  k = iformationService.selectbyifmid(s);
        	if(types.equals("p_weiboType"))
			{
        	s_1=k.getIfm_getBloggerId().split(",");
			}
			else
			{
			s_1 = k.getIfm_notBloggerId().split(",");	
			}
        	if(s_1.length>0)
        	{
        	for(int i=0;i<s_1.length;i++)k_1.add(s_1[i]);
        	//修改博主显示优先级
            if(microuserService.modifyDisplay(1,k_1)){}
        	}
        	}
            if(pageIndex == null || pageIndex <= 0 ){
                pageIndex = 1;
            }
            if(pageSize == null || pageSize <= 0){
                pageSize = 10;
            }
            //分页参数赋值给pageView
            pageView = new PageView(pageSize,pageIndex);
            //转码
            if(microuser_bloggerId != null || "".equals(microuser_bloggerId)){
                microuser_bloggerId = EncodingUtils.fixUrlParamEncoding(request, microuser_bloggerId);
            }
            if(microuser_blogger != null || "".equals(microuser_blogger)){
                microuser_blogger = EncodingUtils.fixUrlParamEncoding(request, microuser_blogger);
            }
            list = microuserService.queryMicroserByType(pageView,microuser_bloggerId, microuser_blogger);
         	//修改博主显示优先级
        	if(!ifm_id.equals(null)&&s_1.length>0&&ifm_id!="")
        	{
            if(microuserService.modifyDisplay(0,k_1)){};
        	}
        } catch (Exception e) {
            log.error("根据参数查询异常");
            log.error(e.getMessage());
            StandardData.setReturnCode(CodeMsg.CODE_EXCEPTION);
            StandardData.setReturnMessage(CodeMsg.MSG_EXCEPTION);
            StandardData.setReturnData(list);
        }
        StandardData.setReturnData(list);
        StandardData.setReturnCode(CodeMsg.CODE_OK);
        StandardData.setReturnMessage(CodeMsg.MSG_OK);
        StandardData.setTotalPages(pageView.getPageCount());
        StandardData.setTotalRecords(pageView.getRowCount());
        return JsonUtils.toString(StandardData,"yyyy-MM-dd HH:mm:ss");
    }
	//导入
	@ResponseBody
	@RequestMapping("importExcelModel")
	public String importExcelModel(HttpServletRequest mrequest,HttpServletResponse response){
		ReturnStandardDataFormat standardData = new ReturnStandardDataFormat(CodeMsg.CODE_ERROR,CodeMsg.MSG_ERROR,null);
		
		String realPath = mrequest.getSession().getServletContext().getRealPath("/uploadTemp/");
		File saveFile = null;
		//如果目录不存在就创建
		if(!new File(realPath).exists()){
			new File(realPath).mkdir();
		}
		saveFile = new File(new File(realPath),
				getUser(mrequest).getUserAccount() + System.currentTimeMillis() + "microuser_temp.xls");
		//把request转型
		DefaultMultipartHttpServletRequest multipartRequest = (DefaultMultipartHttpServletRequest)mrequest;
		//获得文件
		MultipartFile multipartFile = multipartRequest.getFile("importExcel");
		//保存解析出来的信息
		AnalyzeResult<Microuser> analyzeResult = new AnalyzeResult<Microuser>(true,"",new ArrayList<Microuser>());
		//接收导入失败的数据，成功此list的size为0，否则里面的数据为错误数据
		List<Integer> errorIndexList = new ArrayList<Integer>();
		try {
			//转换成file
			multipartFile.transferTo(saveFile);
			//进行数据检测,将数据写入analyzeResult.list中
			microuserService.analyzeExcelData(saveFile, analyzeResult);
			if(analyzeResult.isSuccess()){
				List<Microuser> list = analyzeResult.getList();
				//循环判断是否重复
				for (Microuser microuser : list) {
					if(microuserService.queryByid(null,microuser.getMicrouser_bloggerUrl(),microuser.getMicrouser_blogger(),microuser.getMicrouser_bloggerId())){
						standardData.setReturnCode(CodeMsg.CODE_ERROR_OTHER);
						standardData.setReturnMessage("Excel中博主地址或用户名或用户id有重复值");
						return JsonUtils.toString(standardData, "yyyy-MM-dd HH:mm:ss");
					}
				}
				//通过判断重复值，执行新增
				for (Microuser microuser : list) {
					microuserService.addMicrouser(microuser);
				}
				if(errorIndexList.size() == 0){
					//新增一条操作记录
					//操作日志
					ActiveUser opuser = getUser(mrequest);//获取操作用户
					OptRecord s = new OptClass().goiss(opuser,Menu.Resourceallocation.toString(),
							Menu.microuser.toString(),Operation.daoru.toString(),list.size());
					ioptRecordService.insert(s);	
					//导入数据成功
					standardData.setReturnCode(CodeMsg.CODE_OK);
					standardData.setReturnMessage(CodeMsg.MSG_OK);
				}else{
					ActiveUser opuser = getUser(mrequest);//获取操作用户
					OptRecord s = new OptClass().goiss(opuser,Menu.Resourceallocation.toString(),
							Menu.microuser.toString(),Operation.daoru.toString(),list.size()-errorIndexList.size());
					ioptRecordService.insert(s);	
					//有导入错误返回错误行数
					standardData.setReturnCode(CodeMsg.CODE_ERROR_SAME);
					standardData.setReturnMessage("导入数据完成，存在部分数据导入失败："+errorIndexList.size());
				}
			}else{
				//检测数据失败，返回相应提示信息
				standardData.setReturnCode(CodeMsg.CODE_ERROR_OTHER);
				standardData.setReturnMessage("检测数据格式错误："+analyzeResult.getErrorMessage());
			}	
		} catch (Exception e) {
			log.error("导入微博信息异常");
			ActiveUser opuser = getUser(mrequest);//获取操作用户
			OptRecord s = new OptClass().recordabnormality(opuser,"微博配置导入微博信息异常");
			ioptRecordService.insert(s);
			standardData.setReturnCode(CodeMsg.CODE_ERROR);
			standardData.setReturnMessage(CodeMsg.MSG_ERROR);
		}finally{
			//结束后删除本地文件
			saveFile.delete();
		}
		return JsonUtils.toString(standardData, "yyyy-MM-dd HH:mm:ss");
	}
}
